package com.hspedu.newData.dmsxl.数组;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC605种花问题 {

    // 懒汉式，遇到3个标记位，可以插入的树+1，要注意边界条件
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        if (n==0) return true;
        int count = 0;
        int index = 1;

        for (int i : flowerbed) {
            if (i == 0){
                index++;
            }else {
                index = 0;
            }
            if (index == 3){
                count++;
                index = 1;
                if (count == n){
                    return true;
                }
            }
        }
        if (index == 2){
            count++;
        }
        return count >= n;
    }

    @Test
    public void test() {
        // 测试代码

    }
}
